package com.dzpk.facadeserver.processer;

import com.dzpk.facadeserver.manager.GameServerManager;
import com.dzpk.facadeserver.manager.Token;
import com.dzpk.facadeserver.net.Processer;
import com.dzpk.localprotocol.CyAppStruct;
import com.google.protobuf.InvalidProtocolBufferException;
import org.apache.mina.core.session.IoSession;
import somnus.utility.CommonUtils;

/**
 * Created by somnus on 16/8/22.
 */
public class GetGameIpProcesser extends Processer{
    @Override
    public void process(IoSession session, byte[] data) throws InvalidProtocolBufferException {
        CyAppStruct.GetGameIP getGameIP = CyAppStruct.GetGameIP.parseFrom(data);
        Token token = GameServerManager.getInstance().getServer(getGameIP.getUserId());
        CyAppStruct.GetGameIPResp.Builder builder = CyAppStruct.GetGameIPResp.newBuilder().setIp(token.getServer()).setToken(token.getToken());
        session.write(CommonUtils.getDataPackage(CyAppStruct.MSG.RESP_GET_GAME_IP_VALUE, builder.build().toByteArray()));
    }
}
